Skip to content

chore: simplify, modernize (Go 1.26), update deps#128

Merged
rustatian merged 7 commits into
masterfrom
chore/cleanup-modernize-deps
Jun 2, 2026
Merged

chore: simplify, modernize (Go 1.26), update deps#128
rustatian merged 7 commits into
masterfrom
chore/cleanup-modernize-deps

Conversation

@rustatian
Copy link
Copy Markdown
Member

@rustatian rustatian commented May 29, 2026

Applied fixes

R/High — health.go:27
/health returned 200 during shutdown instead of unavailableStatusCode. Fixed to match /ready behaviour — both now return unavailableStatusCode (503 by default) when shutdown is in progress.

M/Med — plugin.go:68
atomic.Pointer[bool]atomic.Bool. Removes new(bool) allocations and pointer dereferences in Init, Stop, and all three handler constructors (NewHealthHandler, NewReadyHandler, NewJobsHandler). Handler structs updated accordingly; test helper newShutdownPtr updated to match.

R/Med — health.go:111 / ready.go:114
Named-plugin path looked up svc to check ok, then discarded it and re-looked up the same key to call .Status()/.Ready(). Now uses the already-bound svc directly.

M/Low — health.go:111 / ready.go:114 / jobs.go:47
for i := range plg { … plg[i] … }for _, name := range plg (Go 1.22 range-over-value).

R/Med — jobs.go:38
JobsState(context.Background())JobsState(r.Context()) so cancellation propagates from the HTTP request.

Minor
Report slices pre-sized to len(registry) instead of a fixed cap 2.

Deps

go get -u all && go mod tidy on root and tests/; go work sync on the workspace. No version changes were needed (all deps already current).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed graceful shutdown status codes—readiness and jobs endpoints now use the configured unavailable status code instead of hardcoded HTTP 503.
    • Improved request context propagation for job state operations.
  • Tests

    • Added test coverage for plugin initialization error handling and error code mapping.
  • Chores

    • Enhanced CI pipeline with separated unit and e2e test execution and distinct Codecov coverage reports.

- fix: /health returned 200 during shutdown (should be unavailableStatusCode, same as /ready)
- refactor: atomic.Pointer[bool] → atomic.Bool; drop new(bool) stores and pointer derefs
- fix: named-plugin paths used svc from the ok-check then re-looked up via map index — now use svc directly
- modernize: for-index loops over plg slice → range-over-value (Go 1.22)
- fix: jobs handler now threads r.Context() into JobsState instead of context.Background()
- modernize: report slice pre-sized to registry len instead of fixed cap 2
Copilot AI review requested due to automatic review settings May 29, 2026 12:46
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Review Change Stack

Warning

Review limit reached

@rustatian, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 49 minutes and 51 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b48f4a6-3910-488c-904d-bec888f6b0e0

📥 Commits

Reviewing files that changed from the base of the PR and between bf4648a and 01b75f6.

📒 Files selected for processing (4)
  • .github/workflows/linux.yml
  • doc.go
  • plugin.go
  • schema.json
📝 Walkthrough

Walkthrough

This PR refactors the status package to use *atomic.Bool instead of *atomic.Pointer[bool] for shutdown flag management across all HTTP handlers, refactors handler loops to iterate by plugin name, propagates request context through the jobs API, and hardens CI security with separated coverage tracking.

Changes

Atomic Type Migration and Handler Refactoring

Layer / File(s) Summary
Plugin atomic Bool foundation
plugin.go
Plugin.shutdownInitiated changes from *atomic.Pointer[bool] to *atomic.Bool, Init removes explicit false initialization, and Stop calls Store(true) directly on the atomic value.
Test helper and shutdown behavior validation
handler_test.go
newShutdownPtr test helper returns *atomic.Bool, and a comment clarifies liveness remains HTTP 200 during graceful shutdown in the /health endpoint test.
Health handler atomic Bool and loop refactoring
health.go
Health.shutdownInitiated becomes *atomic.Bool, shutdown uses Load(), responds with configured unavailable code, report preallocation matches registry size, and plugin loop iterates by name with explicit lookup and skipping.
Ready handler atomic Bool and loop refactoring
ready.go
Ready.shutdownInitiated becomes *atomic.Bool, shutdown uses Load() and configured unavailable code, report preallocation matches registry size, and plugin loop iterates by name with explicit lookup, nil-handler skip, and header-setting for >= 500 status.
Jobs handler atomic Bool, context propagation, and loop refactoring
jobs.go
Jobs.shutdownInitiated becomes *atomic.Bool, shutdown uses Load(), request context replaces background context for job state retrieval, and report loop uses range-based iteration mapping state fields.
Plugin initialization and RPC error handling tests
plugin_test.go, rpc_test.go
New TestPluginInit with test doubles validates disabled config/unmarshalling errors; new TestConnectCodeFor table-driven test covers plugin-not-found and error mapping to Connect codes.

CI Workflow Security and Coverage Tracking

Layer / File(s) Summary
Workflow permissions and checkout security
.github/workflows/linux.yml
Adds explicit permissions: contents: read and sets persist-credentials: false on checkout to restrict token scope.
Separated coverage profiles and Codecov reporting
.github/workflows/linux.yml
Splits test execution into unit and e2e runs with distinct coverage profiles in coverage-ci/, and generates separate unit.txt and e2e.txt reports for Codecov with path filtering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • roadrunner-server/status#71: Both PRs modify health.go's graceful-shutdown behavior for the /health endpoint—ensuring it returns HTTP 200 while shutdown is active (with the main PR refactoring the shutdown flag handling to support that behavior).
  • roadrunner-server/status#112: Both PRs modify jobs.go's Jobs handler/ServeHTTP logic—main PR changes shutdown-state handling and request context usage, while the retrieved PR adds an early return to avoid nil dereference when statusJobsRegistry is nil.
  • roadrunner-server/status#65: Yes. The main PR centralizes shutdown signaling (Health, Jobs, Ready, Plugin) by using *atomic.Bool and updating ServeHTTP to respect shutdownInitiated, ensuring Status returns 503 during shutdown—directly matching the retrieved PR's goal.

Suggested labels

enhancement

Suggested reviewers

  • wolfy-j

Poem

🐰 A rabbit hops through shutdown flags so bright,
From pointers deep to bools of simpler might!
Each handler now loops by names, not indices—
Request contexts flow where jobs need service,
And workflows stand guard with tighter grip,
Hooray! The status package takes this trip! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely describes the main purpose: code cleanup, Go modernization, and dependency updates. It directly reflects core changes like atomic.Bool refactoring and go get commands.
Description check ✅ Passed The description details applied fixes (shutdown status, atomic types, loop modernization), dependencies, and commits. However, the PR checklist is incomplete—no checkmarks, missing license confirmation text, and 'Reason for This PR' lacks issue reference.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/cleanup-modernize-deps

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modernizes the status service HTTP handlers and plugin shutdown signaling, aiming to reduce allocations, improve correctness during shutdown, and streamline handler logic.

Changes:

  • Replace atomic.Pointer[bool] shutdown flag usage with atomic.Bool across plugin and handlers.
  • Align /health shutdown behavior with configured UnavailableStatusCode, and simplify handler loops / reduce redundant map lookups.
  • Improve handler efficiency and behavior (pre-size report slices, range-over-values, and propagate request cancellation to jobs checks via r.Context()).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
plugin.go Switch shutdown flag storage to atomic.Bool and update handler wiring; adjust shutdown semantics.
health.go Use UnavailableStatusCode on shutdown; pre-size report slice; simplify named-plugin loop and avoid redundant lookups.
ready.go Pre-size report slice; simplify named-plugin loop and avoid redundant lookups; shutdown flag now atomic.Bool.
jobs.go Use request context for JobsState; simplify report building loop; shutdown flag now atomic.Bool.
handler_test.go Update shutdown helper for atomic.Bool and adjust shutdown expectation for /health.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ready.go Outdated
Comment thread jobs.go Outdated
Comment thread plugin.go Outdated
Shutdown path in Ready and Jobs handlers was hard-coding 503 instead of
respecting the handler's configured unavailableStatusCode field, making
the setting ineffective on graceful shutdown. Update the Stop() comment
to match.
@rustatian rustatian self-assigned this Jun 1, 2026
rustatian added 3 commits June 1, 2026 22:37
/health is a liveness probe and must stay 200 while the service drains so
the orchestrator does not kill the draining process; /ready and /jobs
return the configured unavailable code. A prior cleanup collapsed all
three shutdown branches onto unavailableStatusCode, flipping /health to
503 and breaking TestShutdown503.
- connectCodeFor: CodeInternal fallback and wrapped-sentinel unwrap
- Plugin.Init: Disabled when config section missing and on unmarshal error
The coverage job ran go test with -coverpkg=./... from tests/, which
instruments only the tests module (no statements), so codecov received an
empty report.

- run the root unit tests with coverage
- point the e2e -coverpkg at the production module
- upload both profiles for codecov to merge
- add contents: read permissions and persist-credentials: false
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 96.22642% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.43%. Comparing base (09a3f4a) to head (01b75f6).

Files with missing lines Patch % Lines
health.go 95.45% 1 Missing and 1 partial ⚠️
ready.go 95.65% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #128       +/-   ##
===========================================
+ Coverage        0   92.43%   +92.43%     
===========================================
  Files           0        6        +6     
  Lines           0      370      +370     
===========================================
+ Hits            0      342      +342     
- Misses          0       16       +16     
- Partials        0       12       +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

rustatian added 2 commits June 1, 2026 22:47
Align the package doc, schema, and the Stop() comment with the liveness behavior: /ready and /jobs return the configured unavailable code on shutdown while /health stays 200. Also note /jobs honors unavailable_status_code.
The e2e step wrote ../coverage-ci/e2e.out but relied on the unit step's mkdir running first; create the dir in the e2e step too so it is self-contained.
@rustatian rustatian merged commit 269c037 into master Jun 2, 2026
9 checks passed
@rustatian rustatian deleted the chore/cleanup-modernize-deps branch June 2, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants